let express = require('express');
let router = express.Router();
//————————————连接数据库——————————
var mysql = require('mysql');
var connection = mysql.createConnection({
    host: 'localhost',
    user: 'root',
    password: 'password',
    database: 'bookshop'
});

connection.connect((err) => {
    if (err) {
        console.log(err)
    }

});

//获取客户端数据
router.get('/', function (req, response, next) {
    let context = req.query.context
    // console.log(name)
    let contact = req.query.contact
    let user = req.query.user
    // let email = req.query.email
    // let radio = req.query.radio
    console.log(context)
    console.log(contact)
    console.log(user)
    connection.query('INSERT INTO complains SET  ?', { context: context, contact: contact, user: user }, function (err, data) {
        if (err) {
            console.log(err)
            response.send({ statusCode: 0, msg: '提交失败，请重试' })
            return
        } else {
            response.send({ statusCode: 200, msg: '提交成功' })
            return
        }
    })
});
module.exports = router;
